package MouseInheritage;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class MouseUsageDemo {
    public static void main(String[] args) throws Exception {

        boolean UseMouseWithWheel = true;
        boolean UseRightHandOrientedMouse = false;
        boolean UseLeftHandOrientedMouse = false;

        // This bloc demonstrate operations with class MouseWithWheel
        if (UseMouseWithWheel) {
            System.out.println("\nOperation with  \"Mouse with whell\" \n");

            MouseWithWheel wheelMouse = new MouseWithWheel();

            wheelMouse.SetScreenResolution(500, 500);

            wheelMouse.SetColor("Black");

            System.out.println("Mouse color: " + wheelMouse.GetColor());

            System.out.println("\nPerform right button click:");
            wheelMouse.RightButtonClick();

            System.out.println("\nPerform left button click:");
            wheelMouse.LeftButtonClick();

            wheelMouse.TurnWheel(true, 4);
            wheelMouse.TurnWheel(false, 2);
            wheelMouse.TurnWheel(false, -5);

            System.out.println("\n" + wheelMouse.GetScreenResolution());
            System.out.println(wheelMouse.GetMousePosition() + "\n");
            MoveMouseCursor(wheelMouse);
        }

        // This bloc demonstrate operations with class MouseHandOriented
        // Hand orientation - left
        if (UseLeftHandOrientedMouse) {
            System.out.println("\nOperation with  \"Left hand oriented mouse\" \n");

            MouseHandOriented leftHandOrientedMouse = new MouseHandOriented(false, "brown", 1900, 1080);

            System.out.println("Mouse color: " + leftHandOrientedMouse.GetColor());

            System.out.println("\nPerform right button click:");
            leftHandOrientedMouse.RightButtonClick();

            System.out.println("\nPerform left button click:");
            leftHandOrientedMouse.LeftButtonClick();

            System.out.println("\n" + leftHandOrientedMouse.GetScreenResolution());
            System.out.println(leftHandOrientedMouse.GetMousePosition() + "\n");
            MoveMouseCursor(leftHandOrientedMouse);

        }

        // This bloc demonstrate operations with class MouseHandOriented
        // Hand orientation - right
        if (UseRightHandOrientedMouse) {
            System.out.println("\nOperation with  \"Right hand oriented mouse\" \n");

            MouseHandOriented rightHandOrientedMouse = new MouseHandOriented();

            System.out.println("Mouse color: " + rightHandOrientedMouse.GetColor());

            System.out.println("\nPerform right button click:");
            rightHandOrientedMouse.RightButtonClick();

            System.out.println("\nPerform left button click:");
            rightHandOrientedMouse.LeftButtonClick();

            System.out.println("\n" + rightHandOrientedMouse.GetScreenResolution());
            System.out.println(rightHandOrientedMouse.GetMousePosition() + "\n");
            MoveMouseCursor(rightHandOrientedMouse);
        }
    }

    //This method allows users to move the mouse
    static void MoveMouseCursor(Mouse mouse) throws Exception {

        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));

/* delete if not required
        String sX, sY;  //variables for reading user input coordinates
        int x, y;       //variables for transformed coordinates
*/
        String sAnswer; // while "Y" cycle is executed

        do {

            System.out.println("\nEnter parameters of mouse Move(x, y):");

            System.out.println();

            mouse.Move(InputMouseCoordinate(buffer, "x"), InputMouseCoordinate(buffer, "y"));

            System.out.println(mouse.GetMousePosition() + "\n");

            System.out.print("Repeat(Y/N)? ");
            sAnswer = buffer.readLine();

            while(true){
                if (sAnswer.equals("Y") || sAnswer.equals("N"))
                    break;
                else {
                    System.out.print("\r");
                    System.out.print("Please, enter correct data. Repeat (Y/N)? ");
                    sAnswer = buffer.readLine();
                }
            }
        } while (sAnswer.equals("Y"));

    }

    // This method is used to enter coordinates by user
    static int InputMouseCoordinate(BufferedReader buffer, String coordinateName)throws NumberFormatException{

        String sIn; //variables for reading user input coordinates

        while (true) {
            try {
                System.out.print(coordinateName + " = ");
                sIn = buffer.readLine();
                return Integer.parseInt(sIn);
            }catch (NumberFormatException exep){
                System.out.print("Wrong value! Please input number. ");
            }catch(Exception exep){
                System.out.print("Something gone wrong! Please input number. ");
            }
        }

    }
}
